package com.my.zuji.domain.bookkeeping;

import java.math.BigDecimal;
import java.util.Date;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.format.annotation.NumberFormat;
import org.springframework.format.annotation.NumberFormat.Style;

@Entity
@Table(name="bookkeeping")
public class Bookkeeping {
	@Id
	@GeneratedValue
	private Long id;
	
	@ManyToOne
	@JoinColumn(name="user_id",columnDefinition="bigint")
	private User user;
	
	@ManyToOne(cascade= {CascadeType.PERSIST})
	@JoinColumn(name="account_id",columnDefinition="int(11)")
	private Account account;
	
	@ManyToOne
	@JoinColumn(name="member_id",columnDefinition="int(11)")
	private Member member;
	
	@DateTimeFormat(pattern="yyyy-MM-dd")
	@Column(name="create_time",columnDefinition="datetime")
	private Date createTime;
	
	@Column(name="type",columnDefinition="varchar(16)")
	private String type;
	
	@ManyToOne
	@JoinColumn(name="bookingCategory_id",columnDefinition="int(11)")
	private BookingCategory bookingCategory;
	
	@NumberFormat(style=Style.NUMBER)
	@Column(name="amount",columnDefinition="decimal(11,2)")
	private BigDecimal amount;
	
	@ManyToOne
	@JoinColumn(name="project_id",columnDefinition="int(11)")
	private Project project;
	
	@ManyToOne
	@JoinColumn(name="seller_id",columnDefinition="int(11)")
	private Seller seller;

	@Column(name="summary",columnDefinition="varchar(64)")
	private String summary;

	public Bookkeeping(){
		this.createTime = new Date();
	}

	public Bookkeeping(User user){
		this.user = user;
		this.createTime = new Date();
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public Account getAccount() {
		return account;
	}

	public void setAccount(Account account) {
		this.account = account;
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public String getType() {
		return type;
	}

	public void setType(String type) {
		this.type = type;
	}

	public BookingCategory getBookingCategory() {
		return bookingCategory;
	}

	public void setBookingCategory(BookingCategory bookingCategory) {
		this.bookingCategory = bookingCategory;
	}

	public BigDecimal getAmount() {
		return amount;
	}

	public void setAmount(BigDecimal amount) {
		this.amount = amount;
	}

	public Project getProject() {
		return project;
	}

	public void setProject(Project project) {
		this.project = project;
	}

	public Seller getSeller() {
		return seller;
	}

	public void setSeller(Seller seller) {
		this.seller = seller;
	}

	public String getSummary() {
		return summary;
	}

	public void setSummary(String summary) {
		this.summary = summary;
	}

	public Long getId() {
		return id;
	}

	public Member getMember() {
		return member;
	}

	public void setMember(Member member) {
		this.member = member;
	}

}
